WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
isometry_conversions.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "core/common/wolf.h"
24#include "core/math/rotations.h"
25
26namespace wolf
27{
30template <typename D1>
31inline Eigen::Transform<typename D1::Scalar, 2, Eigen::Isometry> toIsometry2d(const Eigen::MatrixBase<D1>& translation,
32 const double& rotation)
33{
35
36 return Eigen::Translation<typename D1::Scalar, 2>(translation) * Eigen::Rotation2D<typename D1::Scalar>(rotation);
37}
38
41template <typename D1, typename D2>
42inline Eigen::Transform<typename D1::Scalar, 2, Eigen::Isometry> toIsometry2d(const Eigen::MatrixBase<D1>& translation,
43 const Eigen::MatrixBase<D2>& rotation)
44{
47
48 return toIsometry2d(translation, rotation(0));
49}
50
53template <typename D1>
54inline Eigen::Transform<typename D1::Scalar, 2, Eigen::Isometry> toIsometry2d(const Eigen::MatrixBase<D1>& trf)
55{
57
58 return toIsometry2d(Eigen::Matrix<typename D1::Scalar, 2, 1>(trf(0), trf(1)), trf(2));
59}
60
63inline Eigen::Isometry2d toIsometry2d(const VectorComposite& trf)
64{
65 return toIsometry2d(trf.at('P'), trf.at('O'));
66}
67
70template <typename D1, typename D2>
71inline Eigen::Transform<typename D1::Scalar, 3, Eigen::Isometry> toIsometry3d(
72 const Eigen::MatrixBase<D1>& translation,
73 const Eigen::QuaternionBase<D2>& rotation)
74{
76
77 return Eigen::Translation<typename D1::Scalar, 3>(translation) * rotation;
78}
79
82template <typename D1, typename D2>
83inline Eigen::Transform<typename D1::Scalar, 3, Eigen::Isometry> toIsometry3d(const Eigen::MatrixBase<D1>& translation,
84 const Eigen::MatrixBase<D2>& rotation)
85{
88
89 return toIsometry3d(
90 translation,
91 Eigen::Quaternion<typename D2::Scalar>(Eigen::Matrix<typename D2::Scalar, 4, 1>(rotation).normalized()));
92}
93
96template <typename D1>
97inline Eigen::Transform<typename D1::Scalar, 3, Eigen::Isometry> toIsometry3d(const Eigen::MatrixBase<D1>& trf)
98{
100 return toIsometry3d(Eigen::Matrix<typename D1::Scalar, 3, 1>(trf(0), trf(1), trf(2)),
101 Eigen::Quaternion<typename D1::Scalar>(trf(6), trf(3), trf(4), trf(5)));
102}
103
106inline Eigen::Isometry3d toIsometry3d(const VectorComposite& trf)
107{
108 return toIsometry3d(trf.at('P'), trf.at('O'));
109}
110
113inline Eigen::Vector3d toVector(const Eigen::Isometry2d& trf)
114{
115 return (Eigen::Vector3d() << trf.translation(), Eigen::Rotation2Dd(trf.rotation()).angle()).finished();
116}
117
120inline Eigen::Vector7d toVector(const Eigen::Isometry3d& trf)
121{
122 return (Eigen::Vector7d() << trf.translation(), Eigen::Quaterniond(trf.rotation()).coeffs().normalized())
123 .finished();
124}
125
128inline Eigen::Isometry3d inverseProjectTo3d(const Eigen::Isometry2d& trf_2d)
129{
130 return Eigen::Translation3d((Eigen::Vector3d() << trf_2d.translation(), 0).finished()) *
131 Eigen::AngleAxisd(Eigen::Rotation2Dd(trf_2d.rotation()).angle(), Eigen::Vector3d::UnitZ());
132}
133
136inline Eigen::Isometry2d projectTo2d(const Eigen::Isometry3d& trf_3d)
137{
138 return Eigen::Translation2d(trf_3d.translation().head<2>()) *
139 Eigen::Rotation2Dd(getYaw(trf_3d.rotation().matrix()));
140}
141
142} // namespace wolf
Composite of state vectors.
Definition: vector_composite.h:29
Matrix< double, 7, 1 > Vector7d
7-vector of real double type
Definition: wolf.h:103
Definition: capture_base.h:23
Eigen::Transform< typename D1::Scalar, 2, Eigen::Isometry > toIsometry2d(const Eigen::MatrixBase< D1 > &translation, const double &rotation)
Isometry 2d from a translation and an angle.
Definition: isometry_conversions.h:31
Eigen::Transform< typename D1::Scalar, 3, Eigen::Isometry > toIsometry3d(const Eigen::MatrixBase< D1 > &translation, const Eigen::QuaternionBase< D2 > &rotation)
Isometry 3d from a translation and a quaternion.
Definition: isometry_conversions.h:71
Eigen::Isometry3d inverseProjectTo3d(const Eigen::Isometry2d &trf_2d)
Isometry 3d of an isometry 2d: in the plane z = 0, rotating about the z axis.
Definition: isometry_conversions.h:128
Eigen::Isometry2d projectTo2d(const Eigen::Isometry3d &trf_3d)
Isometry 2d of an isometry 3d: its x, y translation and its yaw.
Definition: isometry_conversions.h:136
Eigen::MatrixBase< Derived >::Scalar getYaw(const Eigen::MatrixBase< Derived > &_M)
Yaw angle of a rotation matrix or of a quaternion given as a 4-vector [x, y, z, w].
Definition: rotations.h:230
Eigen::Vector3d toVector(const Eigen::Isometry2d &trf)
Pose 3-vector [x, y, theta] of an isometry 2d.
Definition: isometry_conversions.h:113
static void check(const T &t)
Asserts the matrix size dynamically or statically.
Definition: wolf.h:194